
package com.android.finaltracer.ui;

import com.android.finaltracer.MenualViewGroup;
import com.android.finaltracer.R;
import com.android.finaltracer.util.StateSharedPreferences;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.Window;
import android.widget.ImageView;

public class WizardHelpActivity extends Activity {
    private MenualViewGroup menualViewGroup;
    private int[] drawableResources = new int[] {
            R.drawable.manual1,
            R.drawable.manual2, R.drawable.manual3, R.drawable.manual4,
            R.drawable.manual5
    };
    private boolean menual_last = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.wizardhelp);
        menualViewGroup = (MenualViewGroup) findViewById(R.id.menualViewGroup);
        for (int drawableId : drawableResources) {
            ImageView imageView = new ImageView(this);
            imageView.setImageDrawable(getResources().getDrawable(drawableId));
            menualViewGroup.addView(imageView);
        }
        IntentFilter filter = new IntentFilter();
        filter.addAction(MenualViewGroup.ACTION_MENUAL_LAST);
        registerReceiver(broadcastReceiver, filter);
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        unregisterReceiver(broadcastReceiver);
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    // 接收广播
    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action == null) {
                return;
            }
            if (action.equals(MenualViewGroup.ACTION_MENUAL_LAST)) {
                menual_last = true;
                // menualViewGroup.setVisibility(View.GONE);

                StateSharedPreferences.getInstance(WizardHelpActivity.this)
                        .setFirstRunState(false);
                Intent startIntent = new Intent();
                startIntent.setClass(WizardHelpActivity.this,
                        FuncShowTabMainActivity.class);
                startActivity(startIntent);
                finish();

            }
        }
    };
}
